package timing.ukulele.portal.dictionary;

import timing.ukulele.common.dictionary.CodeValueEnum;

import java.util.Arrays;

public enum ResourceMethodEnum implements CodeValueEnum {
    ALL("*", "不限"),
    GET("GET", "GET"),
    POST("POST", "POST"),
    PUT("PUT", "PUT"),
    DELETE("DELETE", "DELETE");

    ResourceMethodEnum(String code, String value) {
        this.code = code;
        this.value = value;
    }

    private String code;
    private String value;

    public static Boolean hasValue(String code) {
        long count = Arrays.stream(values()).filter(item -> item.code.equals(code)).count();
        return count > 0;
    }

    public static String getValueByCode(String code) {
        if (code == null)
            return "未知";
        for (ResourceMethodEnum method : values()) {
            if (method.code.equals(code)) {
                return method.value;
            }
        }
        return "未知";
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getValue() {
        return value;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
